<?php

namespace App\Admin\Extensions;

use App\Models\Statistic;
use Encore\Admin\Layout\Row;
use Encore\Admin\Widgets\Box;
use Encore\Admin\Layout\Column;
use Encore\Admin\Widgets\InfoBox;
use App\Services\Statistics\SearchCount;
use Carbon\Carbon;
use Brick\Math\RoundingMode;


class GoldStatisticsBoxes
{
	public function __construct()
	{
		$this->start = request('start') ?? Carbon::today()->toDateString();
		$this->end = request('end') ?? Carbon::tomorrow()->toDateString();
		$this->gc_group_id = request('gc_group_id') ?? 0;
		$this->result = ['start'=> $this->start , 'end'=> $this->end ,'gc_group_id' => $this->gc_group_id];
		
	}

	public function countBoxes()
	{
		return function (Row $row) {
			
			$this->userCount($row, 2);
			$this->fansCount($row, 2);
			$this->dividendImages($row, 2);
			$this->xhsNum($row, 2);
			$this->dyNum($row, 2);
			$this->ksNum($row, 2);
			$this->sphNum($row, 2);
			$this->xhsFans($row, 2);
			$this->dyFans($row, 2);
			$this->sphFans($row, 2);
			$this->ksFans($row, 2);
		};
	}

	protected function userCount(Row $row, $column)
	{
		$row->column($column, function (Column $column){
			$money = SearchCount::searchUserCount($this->result);
			$box = new InfoBox('用户人数', 'bitcoin', 'purple', '/admin/user', $money);
			$column->append($box);
		});
	}

	protected function fansCount(Row $row, $column)
	{
		$row->column($column, function (Column $column){
			$money = SearchCount::searchFansCount($this->result);
			$box = new InfoBox('加粉合计', 'bitcoin', 'purple', '/admin/user', $money);
			$column->append($box);
		});
	}

	protected function xhsFans(Row $row, $column)
	{
		$row->column($column, function (Column $column){
			//$money = SearchCount::searchXhsFansCount($this->result);

			$money = !empty(SearchCount::searchXhsNum($this->result)) ? big_decimal(SearchCount::searchXhsFansCount($this->result))->dividedBy(SearchCount::searchXhsNum($this->result), 2 , RoundingMode::HALF_UP) : 0;
			$box = new InfoBox('小红书平均加粉数', 'bitcoin', 'purple', '/admin/user', $money);
			$column->append($box);
		});
	}

	protected function dyFans(Row $row, $column)
	{
		$row->column($column, function (Column $column){
			//$money = SearchCount::searchXhsFansCount($this->result);

			$money = !empty(SearchCount::searchDyNum($this->result)) ? big_decimal(SearchCount::searchDyFansCount($this->result))->dividedBy(SearchCount::searchDyNum($this->result), 2 , RoundingMode::HALF_UP) : 0;
			$box = new InfoBox('抖音平均加粉数', 'bitcoin', 'purple', '/admin/user', $money);
			$column->append($box);
		});
	}


	protected function ksFans(Row $row, $column)
	{
		$row->column($column, function (Column $column){
			//$money = SearchCount::searchXhsFansCount($this->result);

			$money = !empty(SearchCount::searchKsNum($this->result)) ? big_decimal(SearchCount::searchKsFansCount($this->result))->dividedBy(SearchCount::searchKsNum($this->result), 2 , RoundingMode::HALF_UP) : 0;
			$box = new InfoBox('快手平均加粉数', 'bitcoin', 'purple', '/admin/user', $money);
			$column->append($box);
		});
	}


	protected function sphFans(Row $row, $column)
	{
		$row->column($column, function (Column $column){
			//$money = SearchCount::searchXhsFansCount($this->result);

			$money = !empty(SearchCount::searchSphNum($this->result)) ? big_decimal(SearchCount::searchSphFansCount($this->result))->dividedBy(SearchCount::searchSphNum($this->result), 2 , RoundingMode::HALF_UP) : 0;
			$box = new InfoBox('视频号平均加粉数', 'bitcoin', 'purple', '/admin/user', $money);
			$column->append($box);
		});
	}

	protected function dividendImages(Row $row, $column)
	{
		$row->column($column, function (Column $column){
			$money = SearchCount::searchDividendImages($this->result);
			$box = new InfoBox('累计图文素材', 'bitcoin', 'purple', '/admin/user', $money);
			$column->append($box);
		});
	}

	protected function xhsNum(Row $row, $column)
	{
		$row->column($column, function (Column $column){
			$money = SearchCount::searchXhsNum($this->result);
			$box = new InfoBox('小红书账号', 'bitcoin', 'purple', '/admin/user', $money);
			$column->append($box);
		});
	}

	protected function dyNum(Row $row, $column)
	{
		$row->column($column, function (Column $column){
			$money = SearchCount::searchDyNum($this->result);
			$box = new InfoBox('抖音账号', 'bitcoin', 'purple', '/admin/user', $money);
			$column->append($box);
		});
	}


	protected function ksNum(Row $row, $column)
	{
		$row->column($column, function (Column $column){
			$money = SearchCount::searchKsNum($this->result);
			$box = new InfoBox('快手账号', 'bitcoin', 'purple', '/admin/user', $money);
			$column->append($box);
		});
	}


	protected function sphNum(Row $row, $column)
	{
		$row->column($column, function (Column $column){
			$money = SearchCount::searchSphNum($this->result);
			$box = new InfoBox('视频号账号', 'bitcoin', 'purple', '/admin/user', $money);
			$column->append($box);
		});
	}


	

	


}
